
import { getEncryptedParam } from './util'
import { getCookie } from '@/utils/cookies'
import { AiSample, ResAiSampleList, AiShareUser, ResAiShare } from '@/types/index'
import { ReqImage, ResImage, ReqImageCheck, ResImageCheck } from '@/types/aiImage'
import qs from 'qs'
import { wxParamType } from '@/types/wx'
import { getQueryVariable } from '@/utils/http'
import { getSignAll } from '@/utils/authApp'
export const hostName = '818ps.com';
export function ipsApi(apiPath: string) { return '//' + hostName + apiPath; }
//|'omit' | 'same-origin'
const options: { credentials: 'include' } = {
    credentials: 'include'
};
const token=getQueryVariable('token') as string;
export interface BaseResponse<T = any> {
    code: number
    msg: string
    data: T
}
export const getxcxjssdk = (): Promise<BaseResponse<wxParamType>> => {
   const resObj= getSignAll('POST','/api/get-xcx-jssdk')
    let url = '';
    if (typeof window != 'undefined') {
        url = document.location.href;

    }
    return fetch('/api/get-xcx-jssdk', {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...resObj},
        method: 'POST',
        body: qs.stringify({ url: url }),
        ...options
    }).then(res => res.json());
}


export const getAidrawSample = (): Promise<BaseResponse<ResAiSampleList>> => { 
    const resObj= getSignAll('GET','/aidraw/sample')
    return fetch('/aidraw/sample?' + qs.stringify({...resObj,pt:'xcx'}), {headers: {...resObj},...options}).then(res => res.json());
}
export const getAidrawShare = (param: { id: string }): Promise<BaseResponse<ResAiShare>> => {
    const resObj= getSignAll('GET','/aidraw/share')
    return fetch('/aidraw/share?' + qs.stringify(param),  {headers: {...resObj},...options}).then(res => res.json());
}


export const getAidrawImage = (pt: string, param: ReqImage): Promise<BaseResponse<ResImage>> => {
    const resObj= getSignAll('POST','/aidraw/image')
    return fetch('/aidraw/image?' + qs.stringify({ pt,...resObj }), {
        headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...resObj},
        method: 'POST',
        body: qs.stringify({ ...param }),
        ...options
    }).then(res => res.json());
}
export const getAidrawCheck = (param: ReqImageCheck): Promise<BaseResponse<ResImageCheck>> => {
    const resObj= getSignAll('GET','/aidraw/check')
    return fetch('/aidraw/check?' + qs.stringify({...param,...resObj}),  {headers: {...resObj},...options}).then(res => res.json());
}

export const aidrawClose = (param: { jobId: string }): Promise<BaseResponse<any>> => {
    const resObj= getSignAll('GET','/aidraw/close')
    return fetch('/aidraw/close?' + qs.stringify({...param,...resObj}),  {headers: {...resObj},...options}).then(res => res.json());
}

export const getAidrawGetNum = (param: { pt: string }): Promise<BaseResponse<any>> => {
    const resObj= getSignAll('GET','/aidraw/get-num')
    return fetch('/aidraw/get-num?' + qs.stringify({...param,...resObj}),  {headers: {...resObj},...options}).then(res => res.json());
}

export default () => { }


